﻿using System;
using System.Configuration;
using System.IO;

namespace OpenExcel_Examples
{
    /// <summary>
    /// Programs using OpenExcel must also refer to these other assemblies:
    /// - WindowsBase
    /// - DocumentFormat.OpenXml (OpenXML SDK 2.0)
    /// </summary>
    class Program
    {
        static void Main(string[] args)
        {
            EnsureOutputDirectoryExists();

            Example1.Run();
            Console.WriteLine("");
            Example2.Run();
            Console.WriteLine("");
            Example3.Run();
            Console.WriteLine("");
            Example4.Run();
            Console.WriteLine("");
            Example5.Run();
            Console.WriteLine("");

            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();
        }

        public static string OutputDirectory
        {
            get
            {
                return ConfigurationManager.AppSettings["WorkingDirectory"];
            }
        }

        public static void EnsureOutputDirectoryExists()
        {
            Directory.CreateDirectory(OutputDirectory);
        }

        public static DateTime LogTime(DateTime dtFrom, string message)
        {
            DateTime dtNext = DateTime.Now;
            Console.WriteLine(string.Format("{0,-40}{1,-20}",
                                            message,
                                            dtNext.Subtract(dtFrom).TotalSeconds + " secs"));
            return dtNext;
        }
    }
}
